import 'package:flutter/material.dart';
import 'package:flutter_douban/config/app_colors.dart';
import 'package:flutter_douban/main_page/store/page/store_product_detail.dart';
import 'package:flutter_douban/model/store_category_model.dart';
import 'package:flutter_douban/tool_views/cached_network_Image.dart';

class StoreShopCell extends StatefulWidget {
  final StoreCategoryModel model;
  final int index;
  const StoreShopCell({Key? key,required this.model,required this.index}) : super(key: key);

  @override
  _StoreShopCellState createState() => _StoreShopCellState();
}

class _StoreShopCellState extends State<StoreShopCell> {
  @override
  Widget build(BuildContext context) {
    return InkWell(
      child: Container(
        color: AppColors.white,
        margin: EdgeInsets.only(top: (widget.index == 0 || widget.index == 1) ? 10 : 0),
        child: Stack(
          children: [
            Column(
              children: [
                Container(
                  margin: EdgeInsets.only(left: widget.index%2 == 0 ? 10 : 5,right:widget.index%2 != 0 ? 10 : 5),
                  child: ClipRRect(
                    child: CachedImage(
                        url: widget.model.ti!,
                        width: (MediaQuery.of(context).size.width - 45) / 2,
                        height: 190),
                    borderRadius: BorderRadius.circular(8),
                  ),
                ),
                SizedBox(
                  height: 8,
                ),
                Container(
                  padding: EdgeInsets.only(left: 10,right: 10),
                  child: Text(
                    widget.model.t!,
                    maxLines: 2,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(
                      fontSize: 15,
                      color: AppColors.black,
                    ),
                  ),
                ),
                SizedBox(
                  height: 8,
                ),
                Container(
                  padding: EdgeInsets.only(left: 10,right: 10),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: [
                      Text(
                        "¥" + widget.model.p!,
                        style: TextStyle(
                          fontSize: 14,
                          color: AppColors.danger,
                        ),
                      ),
                      SizedBox(
                        width: 10,
                      ),
                      Text(
                        "¥" + widget.model.op!,
                        style: TextStyle(
                          fontSize: 12,
                          color: Colors.black45,
                          decoration: TextDecoration.lineThrough,
                          decorationColor: Colors.black45,
                        ),
                      ),
                    ],
                  ),
                )
              ],
            ),
            Positioned(
                top: 8,
                left: widget.index%2 == 0 ? 20 : 16,
                child: Container(
                  height: 18,
                  width: 32,
                  alignment: Alignment.center,
                  decoration: BoxDecoration(
                    color: AppColors.yellow,
                    border: new Border.all(color: AppColors.yellow, width: 1),
                    borderRadius: BorderRadius.circular(3),
                  ),
                  child: Text(
                    '包邮',
                    style: TextStyle(fontSize: 11, color: AppColors.black),
                  ),
                )),
            Positioned(
                top: 160,
                left: widget.index%2 == 0 ? 13 : 8,
                child: Stack(
                  children: [
                    ClipRRect(
                      child: Container(
                        color: Color.fromRGBO(238, 238, 237, 1),
                        height: 30,
                        width: (MediaQuery.of(context).size.width - 44) / 2,
                      ),
                      borderRadius: BorderRadius.only(
                          bottomLeft: Radius.circular(8),
                          bottomRight: Radius.circular(8)),
                    ),
                    Positioned(
                        top: 5,
                        child: Container(
                          width: (MediaQuery.of(context).size.width - 45) / 2,
                          padding: EdgeInsets.only(left: 8,right: 8),
                          child: Text(
                            widget.model.des!,
                            maxLines: 1,
                            overflow: TextOverflow.ellipsis,
                            style: TextStyle(
                              fontSize: 13,
                            ),
                          ),
                        ))
                  ],
                ))
          ],
        ),
      ),
      onTap: (){
        Navigator.of(context).push(MaterialPageRoute(builder: (_) {
          return StoreProductDetail(model: widget.model,);
        }));
      },
    );
  }
}
